//集群监控统计-------------------
//var d_chart6 = document.getElementById('chart6');
//var p_chart6 = document.getElementById('p_chart6');
//var resizeWorldMapContainer6 = function () {
//    d_chart6.style.width = p_chart6.clientWidth +'px';
//    d_chart6.style.height = p_chart6.clientHeight +'px';
//};
//resizeWorldMapContainer6();
//
//var chart6 = echarts.init(d_chart6, 'vintage');
//var option6 = {
//    title :{
//        text: '集群CPU占用率',
//        subtext: '当前作业数/核数',
//        left: 'center'
//    },
//    tooltip : {
//        formatter: "{a} <br/>{b} : {c}%"
//    },
//    toolbox: {
//        feature: {
//            restore: {},
//            saveAsImage: {}
//        }
//    },
//    series: [
//        {
//            name: 'CPU占用率(%)',
//            type: 'gauge',
//            detail: {formatter:'{value}%'},
//            data: [{value: 50, name: '占用率'}]
//        }
//    ]
//};
//chart6.setOption(option6);
//
//var d_chart7 = document.getElementById('chart7');
//var p_chart7 = document.getElementById('p_chart7');
//var resizeWorldMapContainer7 = function () {
//    d_chart7.style.width = p_chart7.clientWidth +'px';
//    d_chart7.style.height = p_chart7.clientHeight +'px';
//};
//resizeWorldMapContainer7();
//
//var chart7 = echarts.init(d_chart7, 'vintage');
//
//chart7.setOption({
//    title :{
//        text: '集群情况',
//        subtext: '当前作业状态及最近一小时完成作业数',
//        left: 'center'
//    },
//    tooltip : {
//        trigger: 'axis',
//        axisPointer : {
//            type : 'shadow'
//        }
//    },
//    toolbox: {
//        show : true,
//        feature : {
//            dataView : {show: true, readOnly: false},
//            restore : {show: true},
//            saveAsImage : {show: true},
//            right: '20%'
//        }
//    },
//    legend: {
//        data:[]
//    },
//    grid: {
//        top: '18%',
//        left: '10%',
//        right: '10%',
//        bottom: '3%',
//        containLabel: true
//    },
//    xAxis : [],
//    yAxis : [],
//    series : []
//});

var d_chart8 = document.getElementById('chart8');
var p_chart8 = document.getElementById('p_chart8');
var resizeWorldMapContainer8 = function () {
    d_chart8.style.width = p_chart8.clientWidth +'px';
    d_chart8.style.height = p_chart8.clientHeight +'px';
};
resizeWorldMapContainer8();

var chart8 = echarts.init(d_chart8, 'vintage');
chart8.setOption({
	 title : {
	        text: '为完成作业信息',
	        subtext: '实时更新',
	        x:'center'
	    },
	    tooltip : {
	        trigger: 'item',
	        formatter: "{a} <br/>{b} : {c} ({d}%)"
	    },
	    legend: {
	        orient: 'vertical',
	        left: 'left',
	        data: ['集群内存平均使用率','空闲']
	    },
	    series : [
	        {
	            name: '集群监控统计',
	            type: 'pie',
	            radius : '55%',
	            center: ['50%', '60%'],
	            data:[],
	            itemStyle: {
	                emphasis: {
	                    shadowBlur: 10,
	                    shadowOffsetX: 0,
	                    shadowColor: 'rgba(0, 0, 0, 0.5)'
	                }
	            }
	        }
	    ]
});
//chart8.setOption({
//    title :{
//        text: '网络监控',
//        subtext: '最近一小时节点平均网络I/O',
//        left: 'center'
//    },
//    tooltip : {
//        trigger: 'axis',
//        axisPointer : {
//            type : 'shadow'
//        }
//    },
//    toolbox: {
//        show : true,
//        feature : {
//            mark : {show: true},
//            dataView : {show: true, readOnly: false},
//            restore : {show: true},
//            saveAsImage : {show: true},
//            right: '20%'
//        }
//    },
//    legend: {
//        data:['in','out','p']
//    },
//    color: ['#cc0d00','#a9c4a9','#0ff300'],
//    grid: {
//        top: '18%',
//        left: '10%',
//        right: '10%',
//        bottom: '3%',
//        containLabel: true
//    },
////    xAxis : [
////        {
////            type : 'category',
////            name : '时间',
////            data : []
////        }
////    ],
////    yAxis : [
////        {
////            type : 'value',
////            name: '平均流量(KB/s)'
////        }
////    ],
//    series : [
//        {
//            name: '集群监控统计',
//            type: 'pie',
//            radius : '55%',
//            center: ['50%', '60%'],
//    
//            itemStyle: {
//                emphasis: {
//                    shadowBlur: 10,
//                    shadowOffsetX: 0,
//                    shadowColor: 'rgba(0, 0, 0, 0.5)'
//                }
//            },
//            data:[
//                {value:30, name:'集群内存平均使用率',itemStyle: {color: '#91c7ae'}},
//                {value:90, name:'空闲',itemStyle: {color: '#f3f3f3'}}
//            ]
//        }
//    ]
//});
var chart8SetOption = function () {
    $.ajax({
        type:"GET",
        url:constUrl+"/monitor/stat/jobs.action",
        dataType:"json",      
        success:function(data){
            if (data.result=="success"){
            	var run = data.message.running;
            	var pend= data.message.pend;
            	var pause=data.message.pause;
//                var ut = data.message.ut;
//                var k = 1 - ut;
                var option_temp = {
                    series : [
                        {
                            data:[
                                {value:run, name:'正在运行作业',itemStyle: {color: '#91c7ae'}},
                                {value:pend, name:'已挂起作业',itemStyle: {color: '#f3f3f3'}},
                                {value:pause, name:'暂停作业',itemStyle: {color: '#913f33'}}
                            ]
                        }
                    ]
                };
                chart8.setOption(option_temp);
            } else {
                layer.msg('CPU使用率获取失败！');
            }
        },
        error:function () {
            layer.msg('CPU使用率获取失败！');
        }
    });
}
chart8SetOption();
interval_8 = window.setInterval("chart8SetOption()", 60000);
var d_chart9 = document.getElementById('chart9');
var p_chart9 = document.getElementById('p_chart9');
var resizeWorldMapContainer9 = function () {
    d_chart9.style.width = p_chart9.clientWidth +'px';
    d_chart9.style.height = p_chart9.clientHeight +'px';
};
resizeWorldMapContainer9();

var chart9 = echarts.init(d_chart9, 'vintage');

chart9.setOption({
	 title : {
	        text: '集群内存平均使用率',
	        subtext: '实时更新',
	        x:'center'
	    },
	    tooltip : {
	        trigger: 'item',
	        formatter: "{a} <br/>{b} : {c} ({d}%)"
	    },
	    legend: {
	        orient: 'vertical',
	        left: 'left',
	        data: ['集群内存平均使用率','空闲']
	    },
	    series : [
	        {
	            name: '集群监控统计',
	            type: 'pie',
	            radius : '55%',
	            center: ['50%', '60%'],
	            data:[],
	            itemStyle: {
	                emphasis: {
	                    shadowBlur: 10,
	                    shadowOffsetX: 0,
	                    shadowColor: 'rgba(0, 0, 0, 0.5)'
	                }
	            }
	        }
	    ]
//    title :{
//        text: '集群内存负载监控',
//        subtext: '当前平均内存使用率',
//        left: 'center'
//    },
//    tooltip : {
//        trigger: 'axis',
//        axisPointer : {
//            type : 'shadow'
//        }
//    },
//    toolbox: {
//        show : true,
//        feature : {
//            dataView : {show: true, readOnly: false},
//            restore : {show: true},
//            saveAsImage : {show: true},
//            right: '20%'
//        }
//    },
//    legend: {
//        data:['运行作业','挂起作业']
//    },
//    grid: {
//        top: '18%',
//        left: '10%',
//        right: '10%',
//        bottom: '3%',
//        containLabel: true
//    },
//    xAxis : [
//        {
//            type : 'category',
//            name : '用户',
//            data : []
//        }
//    ],
//    yAxis : [
//        {
//            type : 'value',
//            name: '作业数(个)'
//        }
//    ],
//    series : []
});
var chart9SetOption = function () {
    $.ajax({
        type:"GET",
        url:constUrl+"/monitor/load/mem.action",
        dataType:"json",      
        success:function(data){
            if (data.result=="success"){
                var ut = data.message.ut;
                var k = 1 - ut;
                var option_temp = {
                    series : [
                        {
                            data:[
                                {value:ut, name:'集群内存平均使用率',itemStyle: {color: '#91c7ae'}},
                                {value:k, name:'空闲',itemStyle: {color: '#f3f3f3'}}
                            ]
                        }
                    ]
                };
                chart9.setOption(option_temp);
            } else {
                layer.msg('CPU使用率获取失败！');
            }
        },
        error:function () {
            layer.msg('CPU使用率获取失败！');
        }
    });
}
chart9SetOption();
interval_2 = window.setInterval("chart9SetOption()", 60000);
var d_chart10 = document.getElementById('chart10');
var p_chart10 = document.getElementById('p_chart10');
var resizeWorldMapContainer10 = function () {
    d_chart10.style.width = p_chart10.clientWidth +'px';
    d_chart10.style.height = p_chart10.clientHeight +'px';
};
resizeWorldMapContainer10();

var chart10 = echarts.init(d_chart10, 'vintage');
chart10.setOption({
    title : {
        text: '集群CPU平均使用率',
        subtext: '实时更新',
        x:'center'
    },
    tooltip : {
        trigger: 'item',
        formatter: "{a} <br/>{b} : {c} ({d}%)"
    },
    legend: {
        orient: 'vertical',
        left: 'left',
        data: ['集群CPU平均使用率','空闲']
    },
    series : [
        {
            name: '集群监控统计',
            type: 'pie',
            radius : '55%',
            center: ['50%', '60%'],
            data:[],
            itemStyle: {
                emphasis: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
        }
    ]
});
var chart10SetOption = function () {
    $.ajax({
        type:"GET",
        url:constUrl+"/monitor/load/cpu.action",
        dataType:"json",      
        success:function(data){
            if (data.result=="success"){
                var ut = data.message.ut;
                var k = 1 - ut;
                var option_temp = {
                    series : [
                        {
                            data:[
                                {value:ut, name:'集群CPU平均使用率',itemStyle: {color: '#91c7ae'}},
                                {value:k, name:'空闲',itemStyle: {color: '#f3f3f3'}}
                            ]
                        }
                    ]
                };
                chart10.setOption(option_temp);
            } else {
                layer.msg('CPU使用率获取失败！');
            }
        },
        error:function () {
            layer.msg('CPU使用率获取失败！');
        }
    });
}
chart10SetOption();
interval_1 = window.setInterval("chart10SetOption()", 60000);

$('#hardwareMonitoring').on('opened.collapse.amui', function() {
//    resizeWorldMapContainer6();
//    chart6.resize();
//    resizeWorldMapContainer7();
//    chart7.resize();
    resizeWorldMapContainer8();
    chart8.resize();
    resizeWorldMapContainer9();
    chart9.resize();
    resizeWorldMapContainer10();
    chart10.resize();
}).on('closed.collapse.amui', function() {
//    resizeWorldMapContainer6();
//    chart6.resize();
//    resizeWorldMapContainer7();
//    chart7.resize();
    resizeWorldMapContainer8();
    chart8.resize();
    resizeWorldMapContainer9();
    chart9.resize();
    resizeWorldMapContainer10();
    chart10.resize();
});

$("#hardwareMonitoringSearch").click(function() {
    $("#hardwareMonitoringIsSearch").val(1);
    $("#hardwareMonitoringStartDateTemp").val($("#hardwareMonitoring-startDate").html());
    $("#hardwareMonitoringEndDateTemp").val($("#hardwareMonitoring-endDate").html());
});
$('#hardwareMonitoring-endDate').text(myDate.getFullYear()+"-"+parseInt(myDate.getMonth()+1)+"-"+myDate.getDate());
$('#hardwareMonitoring-start').datepicker().
on('changeDate.datepicker.amui', function(event) {
    console.log(endDate.valueOf());
    console.log(event.date.valueOf());
    if (event.date.valueOf() > endDate.valueOf()) {
        layer.alert('开始日期应小于结束日期！');
    } else {
        startDate = new Date(event.date);
        $('#hardwareMonitoring-startDate').text($('#hardwareMonitoring-start').data('date'));
    }
    $(this).datepicker('close');
});
$('#hardwareMonitoring-end').datepicker().
on('changeDate.datepicker.amui', function(event) {
    if (event.date.valueOf() < startDate.valueOf()) {
        layer.alert('结束日期应大于开始日期！');
    } else {
        endDate = new Date(event.date);
        $('#hardwareMonitoring-endDate').text($('#hardwareMonitoring-end').data('date'));
    }
    $(this).datepicker('close');
});